#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

struct Cell {
	int r = -1;
	int c = -1;
	Cell* parent = NULL;
	Cell() :r(-1), c(-1), parent(NULL) {}
	Cell(int r, int c, Cell* p) :r(r), c(c), parent(p) {}
};

const int N = 5;
int maze[N][N];
int visited[N][N];
vector<Cell> cells;
int f[4][2] = { {1,0},{0,1},{-1,0},{0,-1} };
int re = N - 1, ce = N - 1;

queue<Cell*> q;

void read_data()
{ 
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < N; ++j)
			cin >> maze[i][j];
	memset(visited, 0, sizeof(visited));
	cells.resize(N * N);
}

bool valid(int r, int c)
{
	return 0 <= r && r < N && 0 <= c && c < N && !visited[r][c] && !maze[r][c];
}

Cell* BFS(int r, int c)
{ 
	int kindex = 0;
	Cell* cell;
	visited[r][c] = 1;
	cells[kindex] =Cell(r, c, NULL);
	q.push(&cells[kindex++]);
	while (!q.empty()) {
		cell = q.front();
		if (cell->r == re && cell->c == ce)
			return cell;
		for (int i = 0; i < 4; ++i)
		{
			int r1 = cell->r + f[i][0];
			int c1 = cell->c + f[i][1];
			if (valid(r1, c1))
			{
				visited[r1][c1] = 1;
				cells[kindex] = Cell(r1, c1, cell);
				q.push(&cells[kindex++]);
			}
		}
		q.pop();
	}
	return NULL;
}

void solve()
{
	auto cell = BFS(0, 0);
	if (cell)
	{
		stack<Cell*> s;
		while (cell) {
			s.push(cell);
			cell = cell->parent;
		}
		while (!s.empty()) {
			cell = s.top();
			cout << "(" << cell->r << ", " << cell->c << ")" << endl;
			s.pop();
		}
	}
}

int main()
{
	freopen("e10-01.txt", "r", stdin);
	read_data();
	solve();
	return 0;
}